package fct.mpc.utils;

import java.util.Random;

public class Snipe {

	private static final int MIN_ATTACK = 75; // Percentage
	private static final int MAX_ATTACK = 100; // Percentage
	private static final int MIN_DEFENSE = 25; // Percentage
	private static final int MAX_DEFENSE = 75; // Percentage
	
	private Random rand = new Random();

	private String name;
	private String element;

	private int level;
	private int health;
	private int attack;
	private int defense;
	private Integer image;

	public boolean caught;

	public Snipe(String name, String element, int level, int health, int attack, int defense, boolean caught) 
	{
		this.name = name;
		this.element = element;
		this.level = level;
		this.health = health;
		this.attack = attack;
		this.defense = defense;
		this.caught = caught;
		
		setImage();	
	}

	public Snipe(String name)
	{
		Snipe base = SnipeCollection.getSnipe(name);
		
		this.name = name;
		this.element = base.getElement();
		this.level = base.getLevel();
		this.health = base.getHealth();
		this.attack = base.getAttack();
		this.defense = base.getDefense();
		this.image = base.getImage();
		
		this.caught = true;
	}
	
	private void setImage()
	{
		if(this.element.equalsIgnoreCase("Air"))
			this.image = fct.mpc.snipehunter.R.drawable.air_anim;
		else if(this.element.equalsIgnoreCase("Electric"))
			this.image = fct.mpc.snipehunter.R.drawable.electric_anim;
		else if(this.element.equalsIgnoreCase("Fire"))
			this.image = fct.mpc.snipehunter.R.drawable.fire_anim;
		else if(this.element.equalsIgnoreCase("Ground"))
			this.image = fct.mpc.snipehunter.R.drawable.ground_anim;
		else if(this.element.equalsIgnoreCase("Ice"))
			this.image = fct.mpc.snipehunter.R.drawable.ice_anim;
		else if(this.element.equalsIgnoreCase("Nature"))
			this.image = fct.mpc.snipehunter.R.drawable.nature_anim;
		else if(this.element.equalsIgnoreCase("Steel"))
			this.image = fct.mpc.snipehunter.R.drawable.steel_anim;
		else if(this.element.equalsIgnoreCase("Water"))
			this.image = fct.mpc.snipehunter.R.drawable.water_anim;
	}

	public String getName() 
	{
		return name;
	}

	public String getElement() 
	{
		return element;
	}

	public int getImage()
	{
		return image;
	}

	public int getLevel()
	{
		return level;
	}

	public int getHealth()
	{
		return health;
	}

	public int getAttack()
	{
		return attack;
	}

	public int getDefense()
	{
		return defense;
	}
	
	public void levelUp()
	{
		this.level++;
	}
	
	public void setHealth(int health)
	{
		this.health = health;
	}
	
	public void setAttack(int attack)
	{
		this.attack = attack;
	}
	
	public void setDefense(int defense)
	{
		this.defense = defense;
	}

	public boolean isCaught()
	{
		return caught;
	}

	@Override
	public String toString()
	{
		return name;
	}

	public String getAsXML()
	{
		String xml = null;

		xml += "\t<snipe>\n";
		xml += "\t\t<name>" + name + "</name>\n";
		xml += "\t\t<element>" + element + "</element>\n";
		xml += "\t\t<level>" + level + "</level>\n";
		xml += "\t\t<health>" + health + "</health>\n";
		xml += "\t\t<attack>" + attack + "</attack>\n";
		xml += "\t\t<defense>" + defense + "</defense>\n";
		xml += "\t\t<caught>" + caught + "</caught>\n";
		xml += "\t</snipe>\n";

		return xml;
	}

	public int attack()
	{
		return attack * (rand.nextInt(MAX_ATTACK - MIN_ATTACK + 1) + MIN_ATTACK) / 100;
	}

	public int defend()
	{
		return defense * (rand.nextInt(MAX_DEFENSE - MIN_DEFENSE + 1) + MIN_DEFENSE) / 100;
	}
}